{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nimport { unstable_useForkRef as useForkRef } from '@mui/utils';\nimport { defaultListboxReducer, useListbox, ActionTypes } from '../ListboxUnstyled';\nfunction stateReducer(state, action) {\n  if (action.type === ActionTypes.blur || action.type === ActionTypes.optionHover || action.type === ActionTypes.setValue) {\n    return state;\n  }\n  const newState = defaultListboxReducer(state, action);\n  if (action.type !== ActionTypes.setHighlight && newState.highlightedValue === null && action.props.options.length > 0) {\n    return _extends({}, newState, {\n      highlightedValue: action.props.options[0]\n    });\n  }\n  return newState;\n}\nexport default function useMenu() {\n  let parameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n  const {\n    listboxRef: listboxRefProp,\n    open = false,\n    onClose,\n    listboxId\n  } = parameters;\n  const [menuItems, setMenuItems] = React.useState({});\n  const listboxRef = React.useRef(null);\n  const handleRef = useForkRef(listboxRef, listboxRefProp);\n  const registerItem = React.useCallback((id, metadata) => {\n    setMenuItems(previousState => {\n      const newState = _extends({}, previousState);\n      newState[id] = metadata;\n      return newState;\n    });\n  }, []);\n  const unregisterItem = React.useCallback(id => {\n    setMenuItems(previousState => {\n      const newState = _extends({}, previousState);\n      delete newState[id];\n      return newState;\n    });\n  }, []);\n  const {\n    getOptionState,\n    getOptionProps,\n    getRootProps,\n    highlightedOption,\n    setHighlightedValue: setListboxHighlight\n  } = useListbox({\n    options: Object.keys(menuItems),\n    optionStringifier: id => {\n      var _menuItems$id$ref$cur;\n      return menuItems[id].label || ((_menuItems$id$ref$cur = menuItems[id].ref.current) == null ? void 0 : _menuItems$id$ref$cur.innerText);\n    },\n    isOptionDisabled: id => {\n      var _menuItems$id;\n      return (menuItems == null ? void 0 : (_menuItems$id = menuItems[id]) == null ? void 0 : _menuItems$id.disabled) || false;\n    },\n    listboxRef: handleRef,\n    focusManagement: 'DOM',\n    id: listboxId,\n    stateReducer,\n    disabledItemsFocusable: true\n  });\n  const highlightFirstItem = React.useCallback(() => {\n    if (Object.keys(menuItems).length > 0) {\n      setListboxHighlight(menuItems[Object.keys(menuItems)[0]].id);\n    }\n  }, [menuItems, setListboxHighlight]);\n  const highlightLastItem = React.useCallback(() => {\n    if (Object.keys(menuItems).length > 0) {\n      setListboxHighlight(menuItems[Object.keys(menuItems)[Object.keys(menuItems).length - 1]].id);\n    }\n  }, [menuItems, setListboxHighlight]);\n  React.useEffect(() => {\n    if (!open) {\n      highlightFirstItem();\n    }\n  }, [open, highlightFirstItem]);\n  const createHandleKeyDown = otherHandlers => e => {\n    var _otherHandlers$onKeyD;\n    (_otherHandlers$onKeyD = otherHandlers.onKeyDown) == null ? void 0 : _otherHandlers$onKeyD.call(otherHandlers, e);\n    if (e.defaultPrevented) {\n      return;\n    }\n    if (e.key === 'Escape' && open) {\n      onClose == null ? void 0 : onClose();\n    }\n  };\n  const createHandleBlur = otherHandlers => e => {\n    var _otherHandlers$onBlur, _listboxRef$current;\n    (_otherHandlers$onBlur = otherHandlers.onBlur) == null ? void 0 : _otherHandlers$onBlur.call(otherHandlers, e);\n    if (!((_listboxRef$current = listboxRef.current) != null && _listboxRef$current.contains(e.relatedTarget))) {\n      onClose == null ? void 0 : onClose();\n    }\n  };\n  React.useEffect(() => {\n    var _listboxRef$current2;\n\n    // set focus to the highlighted item (but prevent stealing focus from other elements on the page)\n    if ((_listboxRef$current2 = listboxRef.current) != null && _listboxRef$current2.contains(document.activeElement) && highlightedOption !== null) {\n      var _menuItems$highlighte, _menuItems$highlighte2;\n      menuItems == null ? void 0 : (_menuItems$highlighte = menuItems[highlightedOption]) == null ? void 0 : (_menuItems$highlighte2 = _menuItems$highlighte.ref.current) == null ? void 0 : _menuItems$highlighte2.focus();\n    }\n  }, [highlightedOption, menuItems]);\n  const getListboxProps = function () {\n    let otherHandlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n    const rootProps = getRootProps(_extends({}, otherHandlers, {\n      onBlur: createHandleBlur(otherHandlers),\n      onKeyDown: createHandleKeyDown(otherHandlers)\n    }));\n    return _extends({}, otherHandlers, rootProps, {\n      role: 'menu'\n    });\n  };\n  const getItemState = id => {\n    const {\n      disabled,\n      highlighted\n    } = getOptionState(id);\n    return {\n      disabled,\n      highlighted\n    };\n  };\n  React.useDebugValue({\n    menuItems,\n    highlightedOption\n  });\n  return {\n    registerItem,\n    unregisterItem,\n    menuItems,\n    getListboxProps,\n    getItemState,\n    getItemProps: getOptionProps,\n    highlightedOption,\n    highlightFirstItem,\n    highlightLastItem\n  };\n}","map":{"version":3,"names":["_extends","React","unstable_useForkRef","useForkRef","defaultListboxReducer","useListbox","ActionTypes","stateReducer","state","action","type","blur","optionHover","setValue","newState","setHighlight","highlightedValue","props","options","length","useMenu","parameters","listboxRef","listboxRefProp","open","onClose","listboxId","menuItems","setMenuItems","useState","useRef","handleRef","registerItem","useCallback","id","metadata","previousState","unregisterItem","getOptionState","getOptionProps","getRootProps","highlightedOption","setHighlightedValue","setListboxHighlight","Object","keys","optionStringifier","_menuItems$id$ref$cur","label","ref","current","innerText","isOptionDisabled","_menuItems$id","disabled","focusManagement","disabledItemsFocusable","highlightFirstItem","highlightLastItem","useEffect","createHandleKeyDown","otherHandlers","e","_otherHandlers$onKeyD","onKeyDown","call","defaultPrevented","key","createHandleBlur","_otherHandlers$onBlur","_listboxRef$current","onBlur","contains","relatedTarget","_listboxRef$current2","document","activeElement","_menuItems$highlighte","_menuItems$highlighte2","focus","getListboxProps","rootProps","role","getItemState","highlighted","useDebugValue","getItemProps"],"sources":["/data/messenger.client/node_modules/@mui/base/MenuUnstyled/useMenu.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport * as React from 'react';\nimport { unstable_useForkRef as useForkRef } from '@mui/utils';\nimport { defaultListboxReducer, useListbox, ActionTypes } from '../ListboxUnstyled';\n\nfunction stateReducer(state, action) {\n  if (action.type === ActionTypes.blur || action.type === ActionTypes.optionHover || action.type === ActionTypes.setValue) {\n    return state;\n  }\n\n  const newState = defaultListboxReducer(state, action);\n\n  if (action.type !== ActionTypes.setHighlight && newState.highlightedValue === null && action.props.options.length > 0) {\n    return _extends({}, newState, {\n      highlightedValue: action.props.options[0]\n    });\n  }\n\n  return newState;\n}\n\nexport default function useMenu(parameters = {}) {\n  const {\n    listboxRef: listboxRefProp,\n    open = false,\n    onClose,\n    listboxId\n  } = parameters;\n  const [menuItems, setMenuItems] = React.useState({});\n  const listboxRef = React.useRef(null);\n  const handleRef = useForkRef(listboxRef, listboxRefProp);\n  const registerItem = React.useCallback((id, metadata) => {\n    setMenuItems(previousState => {\n      const newState = _extends({}, previousState);\n\n      newState[id] = metadata;\n      return newState;\n    });\n  }, []);\n  const unregisterItem = React.useCallback(id => {\n    setMenuItems(previousState => {\n      const newState = _extends({}, previousState);\n\n      delete newState[id];\n      return newState;\n    });\n  }, []);\n  const {\n    getOptionState,\n    getOptionProps,\n    getRootProps,\n    highlightedOption,\n    setHighlightedValue: setListboxHighlight\n  } = useListbox({\n    options: Object.keys(menuItems),\n    optionStringifier: id => {\n      var _menuItems$id$ref$cur;\n\n      return menuItems[id].label || ((_menuItems$id$ref$cur = menuItems[id].ref.current) == null ? void 0 : _menuItems$id$ref$cur.innerText);\n    },\n    isOptionDisabled: id => {\n      var _menuItems$id;\n\n      return (menuItems == null ? void 0 : (_menuItems$id = menuItems[id]) == null ? void 0 : _menuItems$id.disabled) || false;\n    },\n    listboxRef: handleRef,\n    focusManagement: 'DOM',\n    id: listboxId,\n    stateReducer,\n    disabledItemsFocusable: true\n  });\n  const highlightFirstItem = React.useCallback(() => {\n    if (Object.keys(menuItems).length > 0) {\n      setListboxHighlight(menuItems[Object.keys(menuItems)[0]].id);\n    }\n  }, [menuItems, setListboxHighlight]);\n  const highlightLastItem = React.useCallback(() => {\n    if (Object.keys(menuItems).length > 0) {\n      setListboxHighlight(menuItems[Object.keys(menuItems)[Object.keys(menuItems).length - 1]].id);\n    }\n  }, [menuItems, setListboxHighlight]);\n  React.useEffect(() => {\n    if (!open) {\n      highlightFirstItem();\n    }\n  }, [open, highlightFirstItem]);\n\n  const createHandleKeyDown = otherHandlers => e => {\n    var _otherHandlers$onKeyD;\n\n    (_otherHandlers$onKeyD = otherHandlers.onKeyDown) == null ? void 0 : _otherHandlers$onKeyD.call(otherHandlers, e);\n\n    if (e.defaultPrevented) {\n      return;\n    }\n\n    if (e.key === 'Escape' && open) {\n      onClose == null ? void 0 : onClose();\n    }\n  };\n\n  const createHandleBlur = otherHandlers => e => {\n    var _otherHandlers$onBlur, _listboxRef$current;\n\n    (_otherHandlers$onBlur = otherHandlers.onBlur) == null ? void 0 : _otherHandlers$onBlur.call(otherHandlers, e);\n\n    if (!((_listboxRef$current = listboxRef.current) != null && _listboxRef$current.contains(e.relatedTarget))) {\n      onClose == null ? void 0 : onClose();\n    }\n  };\n\n  React.useEffect(() => {\n    var _listboxRef$current2;\n\n    // set focus to the highlighted item (but prevent stealing focus from other elements on the page)\n    if ((_listboxRef$current2 = listboxRef.current) != null && _listboxRef$current2.contains(document.activeElement) && highlightedOption !== null) {\n      var _menuItems$highlighte, _menuItems$highlighte2;\n\n      menuItems == null ? void 0 : (_menuItems$highlighte = menuItems[highlightedOption]) == null ? void 0 : (_menuItems$highlighte2 = _menuItems$highlighte.ref.current) == null ? void 0 : _menuItems$highlighte2.focus();\n    }\n  }, [highlightedOption, menuItems]);\n\n  const getListboxProps = (otherHandlers = {}) => {\n    const rootProps = getRootProps(_extends({}, otherHandlers, {\n      onBlur: createHandleBlur(otherHandlers),\n      onKeyDown: createHandleKeyDown(otherHandlers)\n    }));\n    return _extends({}, otherHandlers, rootProps, {\n      role: 'menu'\n    });\n  };\n\n  const getItemState = id => {\n    const {\n      disabled,\n      highlighted\n    } = getOptionState(id);\n    return {\n      disabled,\n      highlighted\n    };\n  };\n\n  React.useDebugValue({\n    menuItems,\n    highlightedOption\n  });\n  return {\n    registerItem,\n    unregisterItem,\n    menuItems,\n    getListboxProps,\n    getItemState,\n    getItemProps: getOptionProps,\n    highlighted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